package entity_controllers.cards;

import ie.FieldBoard;
import ie.PlayerBoard;
import ie.Shaker;
import dto.Player;
import entity_controllers.Card;

public class BalanceCard extends Card {

	private int amount;
	private boolean fromPlayers;
	
	public BalanceCard(String cardText, int amount) {
		super(cardText);
		this.amount = amount;
		this.fromPlayers = false;
	}
	
	public BalanceCard(String cardText, int amount, boolean fromPlayers) {
		super(cardText);
		this.amount = amount;
		this.fromPlayers = fromPlayers;
	}

	@Override
	public void execute(Player player, FieldBoard fieldBoard, PlayerBoard playerBoard, Shaker shaker) {

		if (fromPlayers == true) {
			// Subtract amount from all players NOTE: This will also subtract the amount from the player who is supposed to receive the money
			for(int i = 0; i < playerBoard.getPlayers().length; i++) {
				playerBoard.getPlayer(i).getAccount().addBalance(-amount); }
			// Add amount multiplied by the amount of players to player NOTE: in some sense the receiving player gives him-/her-self amount
			player.getAccount().addBalance(amount * playerBoard.getPlayers().length);
		}
		else {
			// Add amount to the receiving players account
			if(amount < 0){
				player.getAccount().subBalance(amount*-1);
			}
			else{
				player.getAccount().addBalance(amount);
			}
		}
	}

}
